home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / NextAnswers / 1403_pop-up_list_free_memory_leak.rtf < prev    next >
Text File  |  1993-11-08  |  2KB  |  40 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f3\fmodern Ohlfs;}
  2. \paperw12560
  3. \paperh8740
  4. \margl120
  5. \margr120
  6. {\colortbl;\red0\green0\blue0;\red84\green84\blue84;\red83\green83\blue83;\red82\green82\blue82;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ulnone\fs28\fc0\cf0 Q: I created a 
  8. \fc1\cf1 pop-up list
  9. \fc0\cf0  by dragging it from the InterfaceBuilder palette into a window, but it doesn't seem to be freed when the window is freed. \
  10. \
  11. A:  This is a bug.  Freeing a 
  12. \fc1\cf1 window
  13. \fc0\cf0  
  14. \i does
  15. \i0  free all of its views, but the 
  16. \fc1\cf1 pop-up list
  17. \fc0\cf0  is not a member of the view 
  18. \fc1\cf1 hierarchy
  19. \fc0\cf0 !  It's attached as the target of a Button.   There are two situations in which this bug can bite an unwary programmer:\
  20. \
  21.  
  22. \fi-980\li980 1)    An application creates multiple document windows by loading a nib section multiple times.  In the nib section, there's a 
  23. \fc1\cf1 window
  24. \fc0\cf0  containing a 
  25. \fc1\cf1 pop-up list.  The application leaks a pop-up list instance and a DPS window each time a document is closed.  Furthermore, MallocDebug's "Leaks" button won't find the missing nodes because a pop-up list is a window
  26. \fc0\cf0 , and there are pointers to the missing 
  27. \fc1\cf1 pop-up lists in [NXApp windowList].\
  28. \
  29. 2)    Same situation as in (1), except that each time, the nib section is loaded into a unique zone, and the zones are destroyed when the documents are closed.  Destroying the zone gets rid of all the garbage, but now there are bad pointers in [NXApp windowList].  Some time later, the application crashes in code that you didn't write, referencing objects that you don't know about, leaving you very confused.\
  30.  
  31. \fi0\li0 \
  32. The solution is to free the pop-up list when you free the window.  When setting up the nib file, make an outlet to the Button.  In your code, use the outlet to ask the Button for its target before you free the window.  The target is the pop-up list, which you then free explicitly.\
  33.  
  34. \pard\tx340\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fi-340\li340\fc1\cf1     \
  35. QA809\
  36. \
  37. Valid for 1.0, 2.0, 3.0\
  38. \
  39.  
  40.